from socket import *

yourhostname=input('connect to:')

me=socket(AF_INET,SOCK_STREAM)
me.connect((yourhostname,12345))

cnt=0
while True:
    print(cnt)
    k=5
    d=5
    mhp=3
    yhp=3
    while mhp>0 and yhp>0:
        print(f"You have {k} kill card(s),and {d} dodge card(s)")
        print(f"You have {mhp} hp.Your enemy has {yhp} hp.")
        x=input("input k to kill, d to dodge ,and anything else to pass:")
        if x=='k':
            if k==0:
                print("You have no kill card, you pass this turn.")
                me.send("pass".encode('ASCII'))
            else:
                me.send(str(x).encode('ASCII'))
                k-=1
        elif x=='d':
            if k==0:
                print("You have no dodge card, you pass this turn.")
                me.send("pass".encode('ASCII'))
            else:
                me.send(str(x).encode('ASCII'))
                d-=1
        else:
            print("You pass this turn.")
            me.send("pass".encode('ASCII'))
        y=me.recv(10).decode('ASCII')
        if x=='k':yhp-=1
        if y=='k':mhp-=1
        if x=='d' and y=='k':mhp+=1
        if y=='d' and x=='k':yhp+=1
    if mhp==0 and yhp==0:
        print("draw")
    elif mhp==0:
        print("lose")
        cnt-=1
    else:
        print("win")
        cnt+=1
    
